/*—————————————————————————————————————————————————————————— menu导航栏组件工具 ——————————————————————————————————————————————————————————*/
import {
  getItemInterface,
  combinationItemsInterface,
  combinationItemsType,
} from './interface'

// icon标识内容引入
import { createIcon } from '@/common/icon/index'

// 导航栏渲染成员函数
// --------------------------------------------------------------------------------------------------------
export const getItem: getItemInterface = (
  label,
  key,
  icon,
  children,
  type
) => ({
  label,
  key,
  icon,
  children,
  type,
})

// 导航栏组合成员函数
// --------------------------------------------------------------------------------------------------------
export const combinationItems: combinationItemsInterface = (items) =>
  items.map((val) => {
    // 子集成员承接数组
    let childrenList: combinationItemsType[]

    // 如果此时有子集存在，则进行递归操作
    val.children && (childrenList = combinationItems(val.children))

    // 弹出最终组合的结果
    return getItem(
      val.label,
      val.key,
      val.icon ? createIcon(val.icon) : null,
      childrenList,
      val.type
    )
  })
